package com.ge.myoned.controller;

import com.ge.myoned.dto.BookDto;
import com.ge.myoned.entity.Book;
import com.ge.myoned.service.BookService;
import com.ge.mytestparent.dto.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author geqingxiang
 * @PackageName myProject
 * @Package com.ge.oned.controller
 * @Date 2023/8/4 9:47
 * @Version 1.0
 */
@Tag(name = "ES测试", description = "book")
@RestController
@RequestMapping("book")
public class BookController {

    @Autowired
    public BookService bookService;

    @Operation(summary = "初始化数据")
    @GetMapping("/init")
    public Result<?> init() {
        return bookService.init();
    }

    @Operation(summary = "根据title全文查询")
    @GetMapping("/singleTitle")
    public Result<List<Book>> singleTitle(@Parameter(name = "title", description = "书名") String title, @Parameter(name = "page", description = "页码") Integer page,
                                          @Parameter(name = "pageSize", description = "页面数量") Integer pageSize) {
        return bookService.singleTitle(title, page, pageSize);
    }

    @Operation(summary = "根据字段查询字段值")
    @GetMapping("/singleMatch")
    public Result<List<Book>> singleMatch(@Parameter(name = "match", description = "查询字段") String match, @Parameter(name = "matchValue", description = "查询值") String matchValue,
                                          @Parameter(name = "page", description = "页码") Integer page,
                                          @Parameter(name = "pageSize", description = "页面数量") Integer pageSize) {
        return bookService.singleMatch(match, matchValue, page, pageSize);
    }

    @Operation(summary = "保存")
    @PostMapping("/save")
    public Result save(@RequestBody BookDto bookDto) {
        return bookService.save(bookDto);
    }

    @Operation(summary = "删除全部")
    @DeleteMapping("/delAll")
    public Result delAll() {
        return bookService.delAll();
    }
}
